<template>
  <div>
    <el-container>
      <el-header>

        <div class="BackTitle">
          <BackTitle size="55px"></BackTitle>
        </div>

        <div class="exit" @click="toList">
          退出
        </div>



      </el-header>
      <el-main>
<!--        <router-view></router-view>-->
        <div class="progress-bar-long">
          <div class="progress-bar-short"></div>
        </div>
        <div class="title">
          设置符合活动的分类标签
        </div>
        <div class="description">
          标签数量一般不允许超过三个
        </div>
        <div class="input">
          <el-input
              placeholder="搜索分类标签"
              prefix-icon="el-icon-search"
              v-model="TagKeyword">
          </el-input>
        </div>

        <div class="selectedTag">

          <el-tag @click='cancelTag'
                  v-for="(item,index) in $store.state.editedEvent.topics" :key="index">
                    {{item.label}}
          </el-tag>
          <!--          <el-tag type="success">标签二</el-tag>-->
          <!--          <el-tag type="info">标签三</el-tag>-->
          <!--          <el-tag type="warning">标签四</el-tag>-->
          <!--          <el-tag type="danger">标签五</el-tag>-->
        </div>

        <div class="tag">

          <el-tag @click='selectTag'
                  v-show="item.label.includes(TagKeyword)"
                  v-for="(item,index) in ShowedTags" :key="index">
                    {{item.label}}
          </el-tag>
<!--          <el-tag type="success">标签二</el-tag>-->
<!--          <el-tag type="info">标签三</el-tag>-->
<!--          <el-tag type="warning">标签四</el-tag>-->
<!--          <el-tag type="danger">标签五</el-tag>-->
        </div>
      </el-main>
      <el-footer>

        <div class="button">
          <el-button @click="toDetail1">返回</el-button>
          <el-button @click="toDetail3"> 下一步</el-button>
        </div>

      </el-footer>
    </el-container>
  </div>
</template>

<script>
import BackTitle from "@/components/BackTitle";
import BackButton from "@/components/BackButton";
export default {
  components: {BackButton, BackTitle},
  data() {
    return {
      TagKeyword: '',

      // 利用concat数组连接函数会创建新数组的特性，做到数组浅复制（即会有两个数组）
      ShowedTags: this.$store.state.tags.concat(),
    }
  },
  methods: {
    toList() {
      this.$router.push({
        name:'List'
      })
    },
    toDetail1() {
      this.$router.push({
        name:'Detail1'
      })
    },
    toDetail3(){
      this.$router.push({
        name:'Detail3'
      })

    },
    selectTag(e){
      let vc = this
      this.ShowedTags.forEach(function (tag,index,arr){
        if(tag.value===e.target.innerText){
          arr.splice(index,1)
          vc.$store.state.editedEvent.topics.push(tag)
        }
      })
    },
    cancelTag(e){
      let arr = this.$store.state.editedEvent.topics
      let vc = this
      arr.forEach(function (tag,index,arr){
        if(tag.value===e.target.innerText){
          arr.splice(index,1)
          vc.ShowedTags.push(tag)
        }
      })
    }
  },
}
</script>

<style scoped>
.el-container{
  width: 100%;
  height: 100%;
  position: absolute;
}

.BackTitle{
  /*!*方便观察分区，画出分区边界*!*/
  /*border: 1px solid red;*/

  width: 30%;

  margin-left: -4%;
  margin-top: -1%;
}

.exit{
  /*!*方便观察分区，画出分区边界*!*/
  /*border: 1px solid red;*/

  float:right;

  margin-top: -1.3%;

  font-size: 20px;
}

.button{
  /*!*方便观察分区，画出分区边界*!*/
  /*border: 1px solid red;*/

  float: right;
  margin-right: 7%;
  margin-top: 0.5%;


}

.el-footer{
  border-top-style: solid;
  border-top-width:1px;
  border-top-color:#BBBBBB;
}
.el-button{
  background-color: #F65858;
  color: #fff;

  font-weight: 700;

  border-radius: 5px;;
  border:none;

  width:240px;
  height: 40px;
}

.progress-bar-long{
  /*!*方便观察分区，画出分区边界*!*/
  /*border: 1px solid red;*/

  background-color: #CECECE;

  width: 100%;
  height: 2%;
  position: absolute;
  margin-left: -1.02%;

}

.progress-bar-short{
  /*!*方便观察分区，画出分区边界*!*/
  /*border: 1px solid red;*/
  background-color: #008294;

  width: 20%;
  height: 100%;
  position: absolute;
}

.title{
  /*方便观察分区，画出分区边界*/
  border: 1px solid red;

  position: absolute;
  margin-top: 5%;
  margin-left: 35%;

  font-size: 50px;
  font-weight: 600;
}
.description{
  /*方便观察分区，画出分区边界*/
  border: 1px solid red;

  position: absolute;
  margin-top: 10%;
  margin-left: 40%;

  font-weight: 600;
}

.input{
  /*方便观察分区，画出分区边界*/
  border: 1px solid red;

  position: absolute;
  margin-top: 20%;
  margin-left: 35%;
}

.tag{
  /*方便观察分区，画出分区边界*/
  border: 1px solid red;

  width: 50%;
  height: 30%;
  position: absolute;

  margin-top: 30%;
  margin-left: 35%;

}

.selectedTag{
  /*方便观察分区，画出分区边界*/
  border: 1px solid blue;

  width: 50%;
  height: 30%;
  position: absolute;

  margin-top: 25%;
  margin-left: 35%;
}
</style>
